package com.base.springboot.starter.mybatisplus.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

/**
 * 条件构造器过渡
 *
 * @author admin
 * @date 2020/9/16 上午11:45
 */
public class QueryWrapperTransit<T> {

    private QueryWrapper<T> queryWrapper;

    private GenericService genericService;

    public  QueryWrapperTransit(QueryWrapper<T> queryWrapper, GenericService genericService) {
    }

    /**
     * 等于条件
     *
     * @param fieldName  实体属性名称
     * @param fieldValue 实体属性值
     * @return
     */
    public QueryWrapper<T> eq(String fieldName, Object fieldValue) {
        String tableColumnName = genericService.getColumnName(fieldName);

        this.queryWrapper = this.queryWrapper.eq(tableColumnName, fieldValue);
        return this.queryWrapper;
    }

    /**
     * 模糊条件
     *
     * @param fieldName  实体属性名称
     * @param fieldValue 实体属性值
     * @return
     */
    public QueryWrapper<T> like(String fieldName, Object fieldValue) {
        String tableColumnName = genericService.getColumnName(fieldName);
        this.queryWrapper = this.queryWrapper.like(tableColumnName, fieldValue);
        return this.queryWrapper;
    }

    public QueryWrapper<T> getQueryWrapper() {
        return queryWrapper;
    }
}